package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.StoreService;
import com.tarena.lbs.pojo.basic.param.StoreParam;
import com.tarena.lbs.pojo.basic.param.UserLocationParam;
import com.tarena.lbs.pojo.basic.query.AreaStoreQuery;
import com.tarena.lbs.pojo.basic.query.StoreQuery;
import com.tarena.lbs.pojo.basic.vo.StoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StoreController {
    @Autowired
    private StoreService storeService;
    //查询店铺的分页列表数据
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> storePage(@RequestBody StoreQuery query)
        throws BusinessException{
        PageResult<StoreVO> voPage = storeService.storePage(query);
        return new Result<>(voPage);
    }

    //店铺的新增：
    @PostMapping("/admin/basic/store/add")
    public Result<Void> storeSave(@RequestBody StoreParam param) throws BusinessException{
        storeService.storeSave(param);
        return Result.success();
    }

    //新增文章之前 利用地市id查询店铺列表
    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> getAreaStores(@RequestBody AreaStoreQuery query)
            throws BusinessException{
        PageResult<StoreVO> voPage=storeService.getAreaStores(query);
        return new Result<>(voPage);
    }
    //小程序定位上报
    @PostMapping("/basic/store/location")
    public Result<Void> locationReport(@RequestBody UserLocationParam param)
            throws BusinessException{
        storeService.locationReport(param);
        return Result.success();
    }
}
